/*
	Trivial application that displays a string - 4/96 PNL
*/

public class TrivialApplication {

	static {
		try {
			System.loadLibrary("copytest");	
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}

	public static void main(String args[]) {
		long time;
		int[] intarray = new int[1000];
		int[] intarray2 = new int[1000];
		Stopwatch watch = new Stopwatch().start();
		for(int i=0;i<100000;i++){
			System.arraycopy(intarray,0,intarray2,0,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing arraycopy() = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			for (int j=0;j<1000;j++) {
				intarray2[j] = intarray[j];
			}	
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing assign = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			dumbnativecopy(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing dumbnativecopy() = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativedonothing(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativedonothing() = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativedoabsolutelynothing(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativedoabsolutelynothing() = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativecritical(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativecritical() = "+time);
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativecriticalmemcpy(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativecriticalmemcpy() = "+time);
		watch.stop();
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativepullonly(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativepullonly() = "+time);
		watch.stop();
		watch.reset().start();
		for(int i=0;i<100000;i++){
			nativecriticalpullonly(intarray,intarray2,1000);
		}
		time =watch.getElapsedTime();
		System.out.println("timeusing nativecriticalpullonly() = "+time);
		watch.stop();


	}
	
	public static native void dumbnativecopy(int[] i1, int[] i2, 
		int size);
		
	public static native void lessdumbnativecopy(int[] i1, int[] i2, 
		int size);	
		
	public static native void nativepullonly(int[] i1, int[] i2,
		int size);	
				
	public static native void nativecriticalpullonly(int[] i1, int[] i2,
		int size);		
		
	public static native void nativedonothing(int[] i1, int[] i2, 
		int size);
	public static native void nativedoabsolutelynothing(int[] i1, int[] i2, 
		int size);
	public static native void nativecritical(int[] i1, int[] i2, 
		int size);
	public static native void nativecriticalmemcpy(int[] i1, int[] i2, 
		int size);					
}
